//
//  MouoNavBaseController.m
//  mouo
//
//  Created by tqh on 2016/12/29.
//  Copyright © 2016年 tqh. All rights reserved.
//

#import "IMENavBaseController.h"
#import "UIViewController+BackButtonHandler.h"

@interface IMENavBaseController ()

@end

@implementation IMENavBaseController

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController{
    self = [super initWithRootViewController:rootViewController];
    if (self) {
        //导航栏背景颜色
        self.navigationBar.barTintColor = [UIColor whiteColor];
        self.navigationBar.tintColor = [UIColor colorWithHexString:@"333333"];
        //导航栏左侧侧按钮
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ime_nav_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonEvent)];
        //系统默认的BarButtonItem边距
        self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(0,-10,0,0);
        self.navigationItem.rightBarButtonItem.imageInsets = UIEdgeInsetsMake(0,-10,0,10);

        //修改按钮标题颜色大小
        self.navigationBar.titleTextAttributes =@{NSForegroundColorAttributeName: [UIColor colorWithHexString:@"#333333"],NSFontAttributeName:[IMEFont PingFangSC_MediumWithSize:17]};
        //这行代码可以关闭半透明效果，但是会导致坐标0点移动。
        [UINavigationBar appearance].translucent = NO;
        //关闭坐标0点移动
        self.edgesForExtendedLayout = UIRectEdgeNone;
//        self.delegate = [MouoCommon appdelegate].mainController;
    }
    return self;
}

#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
}

/**重写push方法,让二级界面都没有标签栏*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ime_nav_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonEvent)];
    }
    [super pushViewController:viewController animated:animated];
}

#pragma mark - 事件监听

- (void)backButtonEvent {
    if ([self.viewControllers.lastObject respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {
       [self.viewControllers.lastObject navigationShouldPopOnBackButton];
    }
    [self popViewControllerAnimated:YES];
}

#pragma mark - others 

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (UIViewController *)childViewControllerForStatusBarHidden {
    return self.topViewController;
}

@end
